package  com.rhb.af.web.screen.bean;

import com.rhb.af.util.Format;

public class Field implements java.io.Serializable {
	private String name = "";
	private String type = "";
	private String caption = "";
	private boolean readonly = false;
	private boolean hidden = false;
	private String onblur = "";
	private String selectInput = "";
	private String align = "center";
	private String valign = "middle";
	private String format = "";
	private String onclick = "";
	private String size = "12";
	private boolean sum = false;
	private String formula = "";
	private String tabIndex = "0";
	
	private Object value = null;

	private String query = "";
	
	public Field(){
	}
	
	public Field(String caption,String tabIndex){
		this.caption = caption;
		this.tabIndex = tabIndex;
	}
	
	public Field(Field field){
		name = new String(field.getName());
		caption = new String(field.getCaption());
		type = new String(field.getType());
		readonly = new Boolean(field.isReadonly());
		hidden = new Boolean(field.isHidden());
		onblur = new String(field.getOnblur());
		selectInput = new String(field.getSelectInput());
		align = new String(field.getAlign());
		valign = new String(field.getValign());
		format = new String(field.getFormat());
		onclick = new String(field.getOnclick());
		size = new String(field.getSize());
		sum = new Boolean(field.isSum());
		formula = new String(field.getFormula());
		tabIndex = new String(field.getTabIndex());
		//value = new Object(field.getValue());
		
		query = new String(field.getQuery());
	}
	
	public String getName() {
		return name;
	}
	public void setName(String fieldName) {
		this.name = fieldName;
	}
	public boolean isReadonly() {
		return readonly;
	}
	public void setReadonly(boolean readonly) {
		this.readonly = readonly;
	}
	public boolean isHidden() {
		return hidden;
	}
	public void setHidden(boolean hidden) {
		this.hidden = hidden;
	}
	public String getOnblur() {
		return onblur;
	}
	public void setOnblur(String onblur) {
		this.onblur = onblur;
	}
	public String getSelectInput() {
		return selectInput;
	}
	public void setSelectInput(String selectInput) {
		this.selectInput = selectInput;
	}
	public String getAlign() {
		return align;
	}
	public void setAlign(String align) {
		this.align = align;
	}
	public String getValign() {
		return valign;
	}
	public void setValign(String valign) {
		this.valign = valign;
	}
	public String getOnclick() {
		return onclick;
	}
	public void setOnclick(String onclick) {
		this.onclick = onclick;
	}
	public String getFormat() {
		return format;
	}
	public void setFormat(String format) {
		this.format = format;
	}
	public String getSize() {
		return size;
	}
	public int getSizeOfPx(){
		if(hidden){
			return 0;
		}else{
			return (Integer.parseInt(size)-1)*6+20;
		}
	}
	public void setSize(String size) {
		this.size = size;
	}
	
	public String toString(){
		StringBuffer sb = new StringBuffer();
		sb.append("name=" + name);
		sb.append(",caption=" + caption);
		sb.append(",format=" + format);
		sb.append(",hidden=" + hidden);
		sb.append(",onblur=" + onblur);
		sb.append(",onclick-" + onclick);
		sb.append(",readonly=" + readonly);
		sb.append(",selectInput=" + selectInput);
		sb.append(",size=" + size);
		sb.append(",valign=" + valign);
		sb.append(",tabIndex=" + tabIndex);
		return sb.toString();
	}

	public String getCaption() {
		return caption;
	}

	public void setCaption(String caption) {
		this.caption = caption;
	}

	public boolean isSum() {
		return sum;
	}

	public void setSum(boolean sum) {
		this.sum = sum;
	}

	public String getFormula() {
		return formula;
	}

	public void setFormula(String formula) {
		this.formula = formula;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getTabIndex() {
		return tabIndex;
	}

	public void setTabIndex(String tabIndex) {
		this.tabIndex = tabIndex;
	}
	
	public int getMinTabIndex() {
		if(tabIndex.indexOf(",") != -1){
			String minTabIndex = tabIndex.substring(0,tabIndex.indexOf(","));
			return Integer.parseInt(minTabIndex);
		}else{
			return Integer.parseInt(tabIndex);
		}
	}

	public String getValue() {
		return Format.toString(this.value, this.format);
	}

	public void setValue(Object value) {
		this.value = value;
	}

	public String getQuery() {
		return query;
	}

	public void setQuery(String query) {
		this.query = query;
	}
}
